package com.example.retrofit;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "tag";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        intiview();
    }
    private void intiview(){
        Button b=findViewById(R.id.btn_retrofit);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BaseApplicatiopn.weatherRequest.resquestCityList("f316e87349acc334385260de4a67b6bc")
                        .enqueue(new Callback<BaseList<CityItem>>() {
                    @Override
                    public void onResponse(Call<BaseList<CityItem>> call, Response<BaseList<CityItem>> response) {
                       CityItem[] result= response.body().getResult();
                       for (int i=0;i<result.length;i++){
                           Log.d(TAG, "id= "+result[i].getId()+" province= "+result[i].getProvince()+" city= "+result[i].getCity()+" district= "+result[i].getDistrict());
                       }
                    }

                    @Override
                    public void onFailure(Call<BaseList<CityItem>> call, Throwable t) {

                    }
                });
            }
        });
    }
}